import time
from pyrogram import filters
from pyrogram.types.messages_and_media import Message

from app import app


@app.on_message(filters.me & filters.command("qw"))
async def unsetdajie(client, message: Message):
    from app.libs.spinThePrizeWheel import main as wheel
    from app.libs.spinThePrizeWheel import prizes

    turns = int(message.command[1])
    await message.edit(f"```\n抽奖中```")
    t0 = time.time()
    cost, bonus_back, upload_in_gb, prize_counts = await wheel(turns)
    duration = time.time() - t0
    await message.edit(
        f"抽奖完毕 **{int(cost/1500)}**次 耗时：**{duration:.2f}**秒\n花费 **{(cost/10000):.2f}**w , 返还 **{(bonus_back/10000):.2f}**w , 获得上传 **{upload_in_gb}**gb\n进货价 **{(upload_in_gb/(cost-bonus_back)*10000):.2f}** GB/万灵石\n盈利价 < **{(0.9*upload_in_gb/(cost-bonus_back)*10000):.2f}** GB/万灵石\n\n明细如下：\n"
        + "\n".join(
            [
                f"{prizes[prize]}: {count}"
                for prize, count in prize_counts.items()
                if count > 0
            ]
        )
    )
